Introduce app context switch for setting MSF=true by default#3841
Merged
apoorvdeshmukh merged 3 commits intomainfrom Dec 12, 2025
Merged
Introduce app context switch for setting MSF=true by default#3841apoorvdeshmukh merged 3 commits intomainfrom
apoorvdeshmukh merged 3 commits intomainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces a new app context switch Switch.Microsoft.Data.SqlClient.EnableMSFByDefaultInConnString that allows applications to change the default value of the MultiSubnetFailover connection string property from false to true. This enables parallel IP connection attempts by default in multi-subnet environments, which can improve connection times for Always On availability groups.
Key changes:
- Implements the app context switch following established patterns in the codebase
- Changes
DbConnectionStringDefaults.MultiSubnetFailoverfrom a const to a property that reads the switch value - Adds comprehensive unit tests covering various scenarios including explicit overrides and FailoverPartner validation
- Properly integrates with the existing test infrastructure for app context switch testing
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/LocalAppContextSwitches.cs |
Adds the new app context switch constant, static field, and public property with XML documentation |
src/Microsoft.Data.SqlClient/src/Microsoft/Data/Common/ConnectionString/DbConnectionStringDefaults.cs |
Changes MultiSubnetFailover from const to property that reads from the app context switch |
src/Microsoft.Data.SqlClient/tests/Common/LocalAppContextSwitchesHelper.cs |
Adds test helper infrastructure to manipulate and restore the switch state for testing |
src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft/Data/SqlClient/SqlConnectionStringTest.cs |
Adds comprehensive unit tests for the new switch behavior including edge cases |
src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft/Data/SqlClient/LocalAppContextSwitchesTest.cs |
Updates default value assertion test to include the new switch |
src/Microsoft.Data.SqlClient/tests/Common/LocalAppContextSwitchesHelper.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/LocalAppContextSwitches.cs
Outdated
Show resolved
Hide resolved
paulmedynski
requested changes
Dec 11, 2025
src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/LocalAppContextSwitches.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/LocalAppContextSwitches.cs
Outdated
Show resolved
Hide resolved
...Microsoft.Data.SqlClient/tests/UnitTests/Microsoft/Data/SqlClient/SqlConnectionStringTest.cs
Outdated
Show resolved
Hide resolved
...Microsoft.Data.SqlClient/tests/UnitTests/Microsoft/Data/SqlClient/SqlConnectionStringTest.cs
Outdated
Show resolved
Hide resolved
...soft.Data.SqlClient/src/Microsoft/Data/Common/ConnectionString/DbConnectionStringDefaults.cs
Show resolved
Hide resolved
src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/LocalAppContextSwitches.cs
Show resolved
Hide resolved
src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/LocalAppContextSwitches.cs
Show resolved
Hide resolved
paulmedynski
approved these changes
Dec 11, 2025
src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/LocalAppContextSwitches.cs
Show resolved
Hide resolved
mdaigle
approved these changes
Dec 11, 2025
apoorvdeshmukh
added a commit
that referenced
this pull request
Dec 15, 2025
apoorvdeshmukh
added a commit
that referenced
this pull request
Dec 15, 2025
apoorvdeshmukh
added a commit
that referenced
this pull request
Dec 15, 2025
apoorvdeshmukh
added a commit
that referenced
this pull request
Dec 16, 2025
…by default (#3851) This commit introduces app context switch for setting MultiSubnetFailover=true by default in connection string when the app context switch is set to true. The default value of the context switch is false.
apoorvdeshmukh
added a commit
that referenced
this pull request
Dec 16, 2025
… by default (#3852) This commit introduces app context switch EnableMultiSubnetFailoverByDefault to set MultiSubnetFailover=true in connection string by default when the app context switch is set to true. The default value of this context switch is set to false.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR introduces new app context switch
Switch.Microsoft.Data.SqlClient.EnableMultiSubnetFailoverByDefaultto setMultiSubnetFailover=true by default in connection string.Usage
In application
Or In config file
runtimeconfig.json{ "configProperties": { "Switch.Microsoft.Data.SqlClient.EnableMultiSubnetFailoverByDefault": true } }Or in App.Config
Issues
AB#40809
Testing
Enhanced
LocalAppContextSwitchesTest.csto test new app context switch.Added unit tests in
SqlConnectionStringTest.csGuidelines
Please review the contribution guidelines before submitting a pull request: